package cn.tedu.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.tedu.dao.EmpDao;
import cn.tedu.entity.Dept;
import cn.tedu.entity.Emp;

/**
 * Servlet implementation class AddServlet
 */
public class AddServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取传递过来的内容
		String empno=request.getParameter("empno");
		String ename=request.getParameter("ename");
		String comm=request.getParameter("comm");
		String job=request.getParameter("job");
		String deptno=request.getParameter("deptno");
		Dept dept=new Dept(Integer.parseInt(deptno), null, null);
		Emp e=new Emp(Integer.parseInt(empno), ename, Double.parseDouble(comm), job, dept);
		//调用dao保存
		EmpDao dao=new EmpDao();
		dao.add(e);
		//重定向
		response.sendRedirect(request.getContextPath()+"/index.html");
	}

}
